home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / dino / dino_bot.1 / examples / matvec / ex4.d < prev    next >
Encoding:
Text File  |  1991-03-10  |  3.7 KB  |  108 lines

  1. /* Copyright, 1990, Regents of the University of Colorado */
  2. /* This program computes a matrix - vector product, dividing the matrix into
  3.  * rows, with multiple rows per processor. The matrix is of size M x N,
  4.  * where M must be greater than P, but not necessarily a multiple.  This
  5.  * program uses methodology and functions provided by the map.c include
  6.  * file.  Use of a package along these lines can be helpful when a large
  7.  * number of distributed objects of sizes which are not multiples of the
  8.  * environment structure size are used. */
  9.  
  10. /* A listing of the map.c file appears immediately after this program. */
  11.  
  12. #include "dino.h"
  13.  
  14. #define P 3
  15. #define M 16
  16. #define N 9
  17.  
  18. environment node[P:id] {
  19.  
  20. #include "../inc/map.c"
  21.  
  22.                                 /* ==> Includes the map.c include file.  Since
  23.                                        this file contains code, it must be
  24.                                        included within an environment. */
  25.  
  26.   composite matvec (in a, in x, out y)
  27.   double distributed a[M][N] map BlockRow;      /* Input matrix */
  28.   double distributed x[N] map all;              /* Input vector */
  29.   double distributed y[M] map Block;            /* Result vector */
  30.  
  31.   {
  32.     int i, j;           /* Looping variables */
  33.     map_var a1;                 /* ==> Declares a variable to hold useful
  34.                                        information about an axis of a
  35.                                        distributed data structure which
  36.                                        is [block] mapped. */
  37.  
  38.     /* Setup map_var a1 */
  39.     set_map_var (M,     /* Size of the axis */
  40.                  P,     /* Size of the environment axis it's mapped to */
  41.                  id,    /* Environment index identifier for that axis */
  42.                  0,     /* Left overlap of the mapping function */
  43.                  0,     /* Right overlap of the mapping function */
  44.                  &a1);  /* Address of the map_var */
  45.  
  46.                                 /* ==> This function, defined in map.c, sets
  47.                                        up the map_var a1 to contain information
  48.                                        about the first axis of the distributed
  49.                                        variable a (which is the same as the
  50.                                        only axis of x). */
  51.  
  52.     /* Loop thru the rows of a[][] which are on this environment */
  53.     for (i = a1.left; i <= a1.right; i++) {
  54.  
  55.                                 /* ==> This statement loops thru the correct
  56.                                        rows of a[][] by using information from
  57.                                        a1, the map_var set up earlier.
  58.                                        "a1.left" and "a1.right" refer to the
  59.                                        first and last elements of the "home"
  60.                                        data on this environment */
  61.       /* Compute y[i] */
  62.       y[i] = 0;
  63.       for (j = 0; j < N; j++)
  64.         y[i] += a[i][j] * x[j];
  65.     }
  66.   }
  67. }
  68.  
  69. environment host {
  70.  
  71.   double a[M][N];
  72.   double x[N];
  73.   double y[M];
  74.  
  75.   void main ()
  76.  
  77.   {
  78.     int i, j;           /* Looping variables */
  79.  
  80.     /* Set up the initial data for a[][] and v[] */
  81.     for (j = 0; j < N; j++) {
  82.       x[j] = j;
  83.       for (i = 0; i < M; i++)
  84.         a[i][j] = i + j;
  85.     }
  86.  
  87.     /* Print out the initial data */
  88.     printf ("Initial data for a:\n");
  89.     for (i = 0; i < M; i++) {
  90.       for (j = 0; j < N; j++)
  91.         printf ("%6.2f", a[i][j]);
  92.       printf ("\n");
  93.     }
  94.  
  95.     printf ("\nInitial data for x:\n");
  96.     for (i = 0; i < N; i++)
  97.       printf ("%6.2f\n", x[i]);
  98.  
  99.     /* Perform the computation */
  100.     matvec (a[][], x[], y[])#;
  101.  
  102.     /* Printout the resulting vector y */
  103.     printf ("\nResult data for y:\n");
  104.     for (i = 0; i < M; i++)
  105.       printf ("%6.2f\n", y[i]);
  106.   }
  107. }
  108.